/*!
 * Ext JS Library 3.1
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
Ext.onReady(function(){
    Ext.QuickTips.init();
    var purchaseActions = new Ext.Panel({
        frame:true,
        scripts: true,
        title: '采购系统',
        collapsible:true,
        contentEl:'purchase-actions',
        titleCollapse: true
    });
    
    var warehouseActions = new Ext.Panel({
        frame:true,
        title: '库存系统',
        collapsible:true,
        contentEl:'warehouse-actions',
        titleCollapse: true
    });    

    var salesActions = new Ext.Panel({
        frame:true,
        title: '销售系统',
        collapsible:true,
        contentEl:'sales-actions',
        titleCollapse: true
    });

    var finaceActions = new Ext.Panel({
        frame:true,
        title: '财务系统',
        collapsible:true,
        contentEl:'finance-actions',
        titleCollapse: true
    });
    
    var systemSetupActions = new Ext.Panel({
        frame:true,
        title: '系统设置',
        collapsible:true,
        contentEl:'system-setup',
        titleCollapse: true
    });
    
    var systemServiceActions = new Ext.Panel({
        frame:true,
        title: '系统服务',
        collapsible:true,
        contentEl:'system-service',
        titleCollapse: true
    });

    var actionPanel = new Ext.Panel({
        id:'action-panel',
        region:'west',
        split:true,
        //collapsible: true,
        autoScroll:true,//应对菜单变长
        collapseMode: 'mini',
        width:150,
        minWidth: 150,
        border: false,
        baseCls:'x-plain',
        items: [purchaseActions, warehouseActions, salesActions, finaceActions, systemSetupActions, systemServiceActions]
    });

    //右边工作区的Panel
    var workPanel  = new Ext.Panel({
        frame:true,
        //        autoLoad: {
        //            url: '/house/findHouse',
        //            scripts: true
        //        },
        width:1400,
        title: '工作区',
        collapsible:true,
        titleCollapse: true,
        region:'center'
    });
    //alert(Ext.isAir);
    if(Ext.isAir){ // create AIR window
        var win = new Ext.air.MainWindow({
            layout:'border',
            items: [actionPanel, workPanel],
            title: 'Simple Tasks',
            iconCls: 'icon-show-all'
        }).render();
    }else{
        var viewport = new Ext.Viewport({
            layout:'border',
            //items: [actionPanel, grid]
            items: [actionPanel,workPanel]
        });
    }

    var ab = actionPanel.body;
    ab.on('mousedown', doAction, null, {
        delegate:'a'
    });
    ab.on('click', Ext.emptyFn, null, {
        delegate:'a',
        preventDefault:true
    });
    
    var actions = {
        'sale_order' : function(){
            workPanel.setTitle("销售订单");
            workPanel.getUpdater().update({
                url:'/sale_order/saleOrderList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'opening_stock_list' : function(){
            workPanel.setTitle("期初库存");
            workPanel.getUpdater().update({
                url:'/opening_stock/openingStockList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'opening_stock_audit' : function(){
            workPanel.setTitle("期初审批");
            workPanel.getUpdater().update({
                url:'/opening_stock/openingStockAuditList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'purchase_order_audit' : function(){
            workPanel.setTitle("采购订单审批");
            workPanel.getUpdater().update({
                url:'/purchase_order/purchaseOrderAuditList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        'sale_order_audit' : function(){
            workPanel.setTitle("销售订单审批");
            workPanel.getUpdater().update({
                url:'/sale_order/saleOrderAuditList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'purchase_order' : function(){
            workPanel.setTitle("采购订单");
            workPanel.getUpdater().update({
                url:'/purchase_order/purchaseOrderList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        //库存系统之入库
        'warehouse_entry' : function(){
            workPanel.setTitle("入库记录");
            workPanel.getUpdater().update({
                url:'/warehousing_entry/warehousingEntryList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        //可入库采购订单，查询此列表，可转化销售单为出库单。
        'purchase_orders_for_warehousing': function(){
            workPanel.setTitle("可入库采购订单");
            workPanel.getUpdater().update({
                url:'/purchase_order/purchaseOrderForWarehousingList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        //库存系统之出库
        //可出库销售订单，查询此列表，可转化销售单为出库单。
        'sale_orders_for_delivery': function(){
            workPanel.setTitle("可出库销售订单");
            workPanel.getUpdater().update({
                url:'/sale_order/saleOrderForDeliveryList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        'delivery_order' : function(){
            workPanel.setTitle("仓库出库");
            workPanel.getUpdater().update({
                url:'/delivery_order/deliveryList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        //调拨记录
        'transfer_order' : function(){
            workPanel.setTitle("调拨记录");
            workPanel.getUpdater().update({
                url:'/transfer_order/transferList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        //调拨记录
        'transfer_order_audit' : function(){
            workPanel.setTitle("调拨审批");
            workPanel.getUpdater().update({
                url:'/transfer_order/transferAuditList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        //拆分记录
        'separate_order' : function(){
            workPanel.setTitle("拆分记录");
            workPanel.getUpdater().update({
                url:'/separate_order/separateOrderList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        //产品拆分审批
        'separate_order_audit' : function(){
            workPanel.setTitle("产品拆分审批");
            workPanel.getUpdater().update({
                url:'/separate_order/separateOrderAuditList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        //组合记录
        'assembly_order' : function(){
            workPanel.setTitle("组合记录");
            workPanel.getUpdater().update({
                url:'/assembly_order/assemblyOrderList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        //产品组合审批
        'assembly_order_audit' : function(){
            workPanel.setTitle("产品组合审批");
            workPanel.getUpdater().update({
                url:'/assembly_order/assemblyOrderAuditList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        //库存查询
        'stock_level' : function(){
            workPanel.setTitle("库存查询");
            workPanel.getUpdater().update({
                url:'/stock/index',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        'warehouse_setup' : function(){
            workPanel.setTitle("仓库设置");
            workPanel.getUpdater().update({
                url:'/warehouse/warehouseList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'product_setup' : function(){
            workPanel.removeAll();
            
            workPanel.setTitle("产品设置");
            workPanel.getUpdater().update({
                url:'/product/productsList',
                scope: this,
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'customer_setup' : function(){
            workPanel.setTitle("客户设置");
            workPanel.getUpdater().update({
                url:'/customer/customerList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'vendor_setup' : function(){
            workPanel.setTitle("供应商设置");
            workPanel.getUpdater().update({
                url:'/vendor/vendorList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'system_privilege' : function(){
            workPanel.setTitle("系统权限");
            workPanel.getUpdater().update({
                url:'/privilege/systemPrivilege',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        'role_setup' : function(){
            workPanel.setTitle("角色设置");
            workPanel.getUpdater().update({
                url:'/admin/rolePrivilege',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },

        'department_setup' : function(){
            workPanel.setTitle("部门管理");
            workPanel.getUpdater().update({
                url:'/department/departmentList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        'employee_setup' : function(){
            workPanel.setTitle("用户管理");
            workPanel.getUpdater().update({
                url:'/employee/employeeList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        },
        
        'system_log' : function(){
            workPanel.setTitle("系统日志");
            workPanel.getUpdater().update({
                url:'/admin/logList',
                scripts:true,
                discardUrl:true,
                nocache:true,
                text:"正在载入..."
            });
        }
    };

    function doAction(e, t){
        e.stopEvent();
        actions[t.id]();
    }
});






